/*
 * Created by SharpDevelop.
 * User: fatman
 * Date: 10/27/2008
 * Time: 3:04 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using CUALib;
using System.Drawing;


namespace CUALibTest
{
	class Program
	{
		
		private static Window w=null;
		private static Panel p=null;
		private static TextBox tb=null;
		private static Button b=null;
		
		private static MenuBar mb=null;
		
		
		public static void Main(string[] args)
		{
			//Console.WriteLine( Util.Wrap("askjch asjchasjk hcasjklhdjkvh asdvhasjkvh aksjdvh asjkdvh asjdha",10).Count);
			//Console.ReadLine();
			
			
			
			
			
			
			
			
			
			
			CreateWindowInline();
			//CreateWindowWithFactory();
			if(IsMono())
				loopMono();
			else
				loop();
		}
		
		private static void CreateWindowInline()
		{
			w=new Window(true);
			w.Size=new Size(80,30);
			p=new Panel(true);
			p.Size=new Size(20,20);
			p.Location=new Point(10,2);
			w.Controls.Add(p);
			tb=new TextBox(true);
			tb.Location=new Point(6,3);
			tb.Size=new Size(10,3);
			p.Controls.Add(tb);
			p.Text="0.1.2.3.4.5.";
			p.Text+=p.Text;p.Text+=p.Text;p.Text+=p.Text;p.Text+=p.Text;p.Text+=p.Text;
			tb.Text="Text";
			
			b=new Button(true);
			b.Location=new Point(6,6);
			b.Size=new Size(10,3);
			b.Text="button 1";
			p.Controls.Add(b);
			b.OnClick+=new ButtonOnClick(Button_OnClick);
			
			
			
			mb=new MenuBar(true);
		
			MenuBarItem mbi0=new MenuBarItem(true);
			mbi0.Text="File";
			MenuBarItem mbi1=new MenuBarItem(true);
			mbi1.Text="Edit";
			
			
			mb.Controls.Add(mbi0);
			mb.Controls.Add(mbi1);
			
			
			
			w.Controls.Add(mb);
			
			
			w.DecorationSet=new BoxDrawingDecorationSetAsciiArt();
			w.DecorationSet=new BoxDrawingDecorationSetAlternate();
			w.Invalidate(true);
		}
		
		
		static void Button_OnClick(object sender, EventArgs e)
		{
			((Button)sender).Text=DateTime.Now.ToLongTimeString();
			p.Width+=1;
		}

		
		private static void CreateWindowWithFactory()
		{
			w=CUAWinFormsFactory.CreateFromWindowsForm(typeof(LayoutForms.LayoutForm),10);
			w.Invalidate(true);
			
		}
		
		private static bool IsMono()
		{
			return Type.GetType ("Mono.Runtime") != null;
		}

		private static void loop()
		{
			ConsoleKeyInfo cki = Console.ReadKey(true);
			ConsoleKey ck = cki.Key;
			
			while ( ck != ConsoleKey.Escape)
			{
				w.WndProc(cki);
				cki = Console.ReadKey(true);
				ck = cki.Key;
			}
		}
		
		private static void loopMono()
		{
			//http://lists.ximian.com/pipermail/mono-bugs/2006-October/048897.html
			//Console.ReadKey () appears to not clear key
			while (Console.ReadKey(true).Key!= ConsoleKey.Escape)
			{
				ConsoleKeyInfo cki = Console.ReadKey(true);
				if(cki.Key== ConsoleKey.Escape)
					break;
				w.WndProc(cki);
			}
		}
		
	}
}
